<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/6
 * Time: 20:55
 */


require_once "../config/config.php";
require_once "../model/adminDb.php";
$adminDb = new adminDb();
$id = $_POST['id'];
$val=$_POST['val'];//获取用户状态值的改变
$status=1;
$addtime = time();
$name=$_SESSION['name'];
$userData=$adminDb->query_userName($name);
$userId=$adminDb->queryBug_id($id);
$person=$userId[0]['person'];
$newName=$userId[0]['newName'];

$card=$userData[0]['card'];

if($val=="1" ){
    if($card=="1" || $name==$person || $name==$newName){
        if($name==$newName ||$card=="1"){
            $status=2;
        }
        $addData = $adminDb->edit_status($id,$status);
        try {

            if ($addData) {
                $dat = array(
                    'message' => "更新成功",
                    "code" => 200,

                );
                echo json_encode($dat);
            } else {
                $dat = array(
                    "code" => 404,
                    'message' => "编辑失败",

                );
                echo json_encode($dat);

            }
        } catch (Exception $e) {

            // 回滚事务
            // $pdo->rollback();
            echo $e->getMessage();
        }

    }
    else {
        $dat = array(
            'message' => "操作失败，需管理员或负责人的权限",
            "code" => 102,

        );
        echo json_encode($dat);


    }

}
elseif($val=="3" ){
    if($card=="1" || $name==$person || $name==$newName){
        if($name==$newName ||$card=="1"){
            $status=3;
        }
        $addData = $adminDb->edit_status($id,$status);
        try {

            if ($addData) {
                $dat = array(
                    'message' => "更新成功",
                    "code" => 200,

                );
                echo json_encode($dat);
            } else {
                $dat = array(
                    "code" => 404,
                    'message' => "编辑失败",

                );
                echo json_encode($dat);

            }
        } catch (Exception $e) {

            // 回滚事务
            // $pdo->rollback();
            echo $e->getMessage();
        }

    }
    else {
        $dat = array(
            'message' => "操作失败，需管理员或负责人的权限",
            "code" => 102,

        );
        echo json_encode($dat);


    }

}
else {
    if($card=="1" || $name==$person || $name==$newName){
        $status=0;
        $addData = $adminDb->edit_status($id,$status);
        try {

            if ($addData) {
                $dat = array(
                    'message' => "更新成功",
                    "code" => 200,

                );
                echo json_encode($dat);
            } else {
                $dat = array(
                    "code" => 404,
                    'message' => "编辑失败",

                );
                echo json_encode($dat);

            }
        } catch (Exception $e) {

            // 回滚事务
            // $pdo->rollback();
            echo $e->getMessage();
        }

    }
    else {
        $dat = array(
            'message' => "操作失败，需管理员或负责人的权限",
            "code" => 102,

        );
        echo json_encode($dat);


    }

}























